<template>
  <div class="mod-config">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()" style="margin-top: 20px">
      <el-form-item>
        <el-input v-model="dataForm.key" placeholder="客人姓名/房间号" clearable></el-input>
      </el-form-item>
      <el-form-item label="" v-if="isAuth('hotel:hotelseller:list')">
        <selectSeller @change="selectSellerChange"></selectSeller>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">查询</el-button>
        <el-button v-if="isAuth('hotel:tguestitems:save')" type="primary" @click="addOrUpdateHandle()">新增</el-button>
        <el-button>
          导出
        </el-button>
        <el-button @click="print('tguestitems')">
          打印
        </el-button>
        <el-button v-if="isAuth('hotel:tguestitems:delete')" type="danger" @click="deleteHandle()" :disabled="dataListSelections.length <= 0">批量删除</el-button>
      </el-form-item>
    </el-form>
    <div  class="print-only">
      <el-table :data="dataList" border v-loading="dataListLoading" @selection-change="selectionChangeHandle" style="width: 100%;" id="tguestitems">
        <el-table-column type="selection" header-align="center" align="center" width="50">
        </el-table-column>
        <el-table-column prop="name" header-align="center" align="center" label="物品名称">
        </el-table-column>
        <el-table-column prop="type" header-align="center" align="center" label="物品类型">
          <template slot-scope="scope">
          <span v-if="scope.row.type=='1'">
            贵重物品
          </span>
            <span v-if="scope.row.type=='2'">
            遗失物品
          </span>
          </template>
        </el-table-column>
        <el-table-column prop="fname" header-align="center" align="center" label="客人姓名">
        </el-table-column>
        <el-table-column prop="ftel" header-align="center" align="center" label="客人电话">
        </el-table-column>
        <el-table-column prop="pfno" header-align="center" align="center" label="客人房间号">
        </el-table-column>
        <el-table-column prop="createTime" header-align="center" align="center" label="物品存放时间">
        </el-table-column>
        <el-table-column prop="krType" header-align="center" align="center" label="客人类型">

          <template slot-scope="scope">
          <span v-if="scope.row.krType=='0'">
            在住客人
          </span>
            <span v-if="scope.row.krType=='1'">
            离店客人
          </span>
            <span v-if="scope.row.krType=='2'">
            其他
          </span>
          </template>
        </el-table-column>

        <el-table-column prop="sdjdh" header-align="center" align="center" label="登记单号">
        </el-table-column>

        <el-table-column prop="money" header-align="center" align="center" label="参考价值">
        </el-table-column>
        <el-table-column prop="creatUserName" header-align="center" align="center" label="存放操作员">
        </el-table-column>
        <el-table-column prop="updateTime" header-align="center" align="center" label="领取时间">
        </el-table-column>
        <el-table-column prop="updateUserName" header-align="center" align="center" label="领取操作员">
        </el-table-column>

        <el-table-column prop="lqr" header-align="center" align="center" label="领取人">
        </el-table-column>

        <el-table-column prop="remake" header-align="center" align="center" label="备注">
        </el-table-column>
        <el-table-column fixed="right" header-align="center" align="center" width="150" label="操作">
          <template slot-scope="scope">
            <el-button type="text" size="small" v-if="scope.row.islq=='0'" @click="lq(scope.row)">领取</el-button>
            <el-button type="text" size="small" @click="addOrUpdateHandle(scope.row.id)">修改</el-button>
            <el-button type="text" size="small" @click="deleteHandle(scope.row.id)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>

    <el-pagination @size-change="sizeChangeHandle" @current-change="currentChangeHandle" :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]" :page-size="pageSize" :total="totalPage" layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>

    <el-dialog title="领取" :visible.sync="showlq" v-if="showlq" width="30%">
      <el-input v-model="item.lqr" placeholder="领取人"></el-input>
      <span slot="footer" class="dialog-footer">
        <el-button @click="showlq = false">取消</el-button>
        <el-button type="primary" @click="updateid(item)">确定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
  import AddOrUpdate from './tguestitems-add-or-update'
  import {printExcel} from "@/utils/printExcel";
  export default {
    data() {
      return {
        dataForm: {
          key: ''
        },
        dataList: [],
        sellerIds: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        dataListSelections: [],
        addOrUpdateVisible: false,
        showlq: false,
      }
    },
    components: {
      AddOrUpdate
    },
    activated() {
      this.getDataList()
    },
    methods: {
      lq(item) {
        this.item = item;
        this.showlq = true;
      },
      selectSellerChange(val) {
        console.log("接收值", val);
        this.sellerIds = val;
        this.getDataList();
      },
      //打印
      print(id){
        // printExcel(id)
        window.print();
      },
      // 获取数据列表
      getDataList() {
        this.dataListLoading = true
        this.$http({
          url: this.$http.adornUrl('/hotel/tguestitems/list'),
          method: 'get',
          params: this.$http.adornParams({
            'page': this.pageIndex,
            'limit': this.pageSize,

            'sellerIds': this.sellerIds.join(","),
            ...this.dataForm,
          })
        }).then(({
          data
        }) => {
          if (data && data.code === 0) {
            this.dataList = data.page.list
            this.totalPage = data.page.totalCount
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
      },
      // 表单提交
      updateid(item) {
        this.$http({
          url: this.$http.adornUrl(`/hotel/tguestitems/updateByid`),
          method: 'post',
          data: item
        }).then(({
          data
        }) => {
          if (data && data.code === 0) {
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {
                this.showlq = false;
                this.getDataList();
              }
            })
          } else {
            this.$message.error(data.msg)
          }
        })
      },
      // 每页数
      sizeChangeHandle(val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle(val) {
        this.pageIndex = val
        this.getDataList()
      },
      // 多选
      selectionChangeHandle(val) {
        this.dataListSelections = val
      },
      // 新增 / 修改
      addOrUpdateHandle(id) {
        this.addOrUpdateVisible = true
        this.$nextTick(() => {
          this.$refs.addOrUpdate.init(id)
        })
      },
      // 删除
      deleteHandle(id) {
        var ids = id ? [id] : this.dataListSelections.map(item => {
          return item.id
        })
        this.$confirm(`确定对[id=${ids.join(',')}]进行[${id ? '删除' : '批量删除'}]操作?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$http({
            url: this.$http.adornUrl('/hotel/tguestitems/delete'),
            method: 'post',
            data: this.$http.adornData(ids, false)
          }).then(({
            data
          }) => {
            if (data && data.code === 0) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.getDataList()
                }
              })
            } else {
              this.$message.error(data.msg)
            }
          })
        })
      }
    }
  }
</script>
<style>
/* @media print 规则来仅打印.print-only div */
@media print {
  /* 隐藏所有其他元素 */
  body * {
    visibility: hidden;
  }

  /* 显示.print-only div及其子元素 */
  .print-only, .print-only * {
    visibility: visible;
  }

  .chapter-break {
    page-break-before: always;
  }
  /* 如果需要，可以进一步调整.print-only div的样式 */
  .print-only {
    position: absolute; /* 根据需要设置 */
    left: 0;
    top: 0;
    /* 其他打印样式 */
  }
}
</style>
